package com.ruoyi.web.controller.charge;

import com.ruoyi.charge.domain.ChargeOrder;
import com.ruoyi.charge.service.OrderService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("charge/order")
public class OrderController extends BaseController {
    @Autowired
    private OrderService orderService;

    @PreAuthorize("@ss.hasPermi('charge:order:add')")
    @Log(title = "处方订单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody ChargeOrder chargeOrder) {
        chargeOrder.setCreateBy(getUsername());
        return success(orderService.addOrder(chargeOrder));
    }

    @PreAuthorize("@ss.hasPermi('charge:order:edit')")
    @Log(title = "处方订单", businessType = BusinessType.UPDATE)
    @GetMapping
    public AjaxResult edit(Long pid) {
        return toAjax(orderService.updateOrder(pid));
    }

}
